package com.hnxxxy.workshop.exception;



import com.hnxxxy.workshop.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * @description: 异常处理
 * @author: zqh
 * @date: 2022/1/10 11:28
 **/
@ControllerAdvice
@Slf4j
public class ExceptionHandle {

    /**
     * 全局异常
     * @param e
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public R Handle(Exception e) {
        //是不是自定义异常
        if (e instanceof BizException) {
            BizException bizException = (BizException) e;
            log.info("[业务异常]{}", e);
            return R.buildError(bizException.getMsg());

        } else {
            log.info("[系统异常]{}", e);
            return R.buildError("全局异常，未知错误");
        }

    }

}
